public class Complex {
    double r;
    double i;
    public Complex(){
    }
    public Complex(double r,double i){
        this.r = r;
        this.i = i;
    }
    public static double getRealPart(double r) {
        return r;
    }
    public static double getImagePart(double i) {
        return i;
    }

    //Override Object
    public boolean equals(Complex a){
        return (this.r==a.r&&this.i==a.i);
    }
    @Override
    public String toString(){
        String s = " ";
        if(this.i<0)
             s=this.r+""+this.i+"i";
        else if(this.i==0)
            s=this.r+"";
        else if(this.i>0)
            s=this.r+"+"+this.i+"i";
        return s;
    }
    // 定义公有方法:加减乘除
    Complex ComplexAdd(Complex c) {
        return new Complex(r + c.r, i + c.i);
    }
    Complex ComplexSub(Complex c) {
        return new Complex(r - c.r, i - c.i);
    }
    public Complex ComplexMulti(Complex c) {
        return new Complex(r * c.r - i * c.i, r * c.i + i * c.r);
    }
    public Complex ComplexDiv(Complex c) {
        return new Complex((r * c.i + i * c.r)/(c.i * c.i + c.r * c.r), (i * c.i + r * c.r)/(c.i * c.i + c.r * c.r));
    }

}
